package com.jackrain.nea.fc.ps.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.jdbc.SQL;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Mapper
public interface ViewCprodimMapper {


    /**
     * 查询
     *
     * @param param
     * @return List<HashMap>
     */
    @SelectProvider(type = ViewCprodimMapper.ViewCprodimSqlProvider.class,
            method = "selectprodimsql")
    HashMap selectprodimsql(@Param("list") Object[] param);

    /**
     * 查询
     *
     * @param param
     * @return List<HashMap>
     */
    @SelectProvider(type = ViewCprodimMapper.ViewCprodimSqlProvider.class,
            method = "selectprodimiteamsql")
    List<HashMap> selectprodimiteamsql(@Param("list") Object[] param);

    class ViewCprodimSqlProvider {

        public String selectprodimsql(final Map<String, Object> map) {
            return new SQL() {
                {
                    String colum = " AD_PROCOLUMN_NAME,ENAME ";
                    SELECT(colum);
                    FROM("PS_C_PRODIM");
                    Object[] list = (Object[]) map.get("list");
                    StringBuilder sb = new StringBuilder("(");
                    for (Object num : list) {
                        sb.append(num).append(",");
                    }
                    sb.deleteCharAt(sb.length() - 1).append(")");
                    WHERE(" ID IN " + sb.toString());

                }
            }.toString();
        }

        public String selectprodimiteamsql(final Map<String, Object> map) {
            return new SQL() {
                {
                    String colum = " ECODE,ENAME,ORDERNO,ISACTIVE,MODIFIEDDATE,MODIFIERENAME ";
                    SELECT(colum);
                    FROM("PS_C_PRODIM_ITEM");
                    Object[] list = (Object[]) map.get("list");
                    StringBuilder sb = new StringBuilder("(");
                    for (Object num : list) {
                        sb.append(num).append(",");
                    }
                    sb.deleteCharAt(sb.length() - 1).append(")");
                    WHERE(" ID IN" + sb.toString());
                }
            }.toString();
        }
    }

}
